<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>建造者模式</title>
</head>
<body>
<script>
    //1.产出是房子
    //2.包工头调用工人进行开工，而且很清楚工人们具体的某一大项分工
    //3.工人是盖房子的，工人可以建卧室、客厅、厨房
    //4.包工头只是一个接口而已，他不干活，只对外说他能建房子
    function Fangzi(){//Fangzi可以理解为单例模式
        if(!(this instanceof Fangzi)){
            return new Fangzi();
        }
        this.woshi="";
        this.keting="";
        this.chufang="";

    }
    function Baogongtou(){
        if(!(this instanceof Baogongtou)){
            return new Baogongtou();
        }
        this.jianfangzi=function(gongren){
            gongren.jian_chufang();
            gongren.jian_keting();
            gongren.jian_woshi();
        }
    }
    function Gongren(){
        if(!(this instanceof Gongren)){
            return new Gongren();
        }
        this.jian_woshi=function(){
            console.log("建卧室");
        }
        this.jian_keting=function(){
            console.log("建客厅");
        }
        this.jian_chufang=function(){
            console.log("建客厅");
        }
        this.jiaofang=function(){
            var _fangzi= new Fangzi();
            _fangzi.woshi="ok";
            _fangzi.keting="ok";
            _fangzi.chufang="ok";
            return _fangzi;
        }
    }
    var gongren = new Gongren();
    var baogongtou=new Baogongtou();
    baogongtou.jianfangzi(gongren);
    var myfangzi=gongren.jiaofang();
    console.log(myfangzi);
</script>
</body>
</html>